package com.lagou.distribution.web;


import com.lagou.distribution.dao.ResumeRepository;
import com.lagou.distribution.model.Resume;
import com.lagou.distribution.pojo.User;
import com.lagou.distribution.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class DistributionController {

    @Autowired
    ResumeRepository resumeRepository;

    @Autowired
    private UserService service;

    @GetMapping("toLogin")
    public String login() {
        return "login";
    }

    @PostMapping("login")
    public String login(@RequestParam("name") String name,
                        @RequestParam("pwd") String pwd, HttpSession session) {
        User user = service.login(name, pwd);
        if (null != user) {
            session.setAttribute("isLogin", "true");
            return "success";
        }

        return "failure";
    }

    @GetMapping("/resumes")
    @ResponseBody
    public List<Resume> resumes() {
        System.err.println("8080");
        return resumeRepository.findAll();
    }
}
